/**
 * Below is a sample adapter for connecting with a webservice.
 */

var paymentAdapter={
    server:BASE_URL,
    save:function(obj,callback,foo){
        $.get(this.server+"todo.php?axt=save&data="+encodeURIComponent(JSON.stringify(obj)),
            function(id){
                obj.id=id;
                $(document).trigger(obj.name + ":save", obj);
                if(callback)
                    callback(obj);
            }
        );
    },
    fetch:function(item,callback){
        $.get(BASE_URL+"payment?id="+encodeURIComponent(item.id),
            function(obj){
                
                obj=JSON.parse(obj);
                if(callback)
                    callback(obj);
            }
        );
    },
    fetchAll:function(id,callback){
        $.get(BASE_URL+"payments",
            function(obj){
                obj=JSON.parse(obj);
                if(callback)
                    callback(obj);
            }
        );
    },
    remove:function(obj,callback){
        $.get(BASE_URL+"todo.php?axt=delete&data="+encodeURIComponent(obj.id),
            function(obj){
                $(document).trigger(obj.name + ":remove", obj.id);
                obj=JSON.parse(obj);
                if(callback)
                    callback(obj);
            }
        );
    }
}


Payment =  $.mvc.model.extend("payment",{
    validate:function(opts){
        if(opts&&opts.trigger)
            return "error validating";
        return true;
    },
    payment_id: '',
    payment_code: '',
    payment_name: '',
    payment_desc: '',
    payment_logo: '',
    description: ''
}, paymentAdapter);

var payment = new Payment();